package com.xiaoxin.controller;

import com.xiaoxin.interceptor.UserHolder;
import com.xiaoxin.model.domain.UserInfo;
import com.xiaoxin.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @author xiaoxiaode
 * @date 2021-08-29-13:32
 **/
@RestController
@RequestMapping("/user")
public class UserInfoController {

    @Autowired
    private UserInfoService userInfoService;

    /*
     * 完善资料
     * 请求头中包含token
     * */
    @PostMapping("/loginReginfo")
    public ResponseEntity loginReginfo(@RequestBody UserInfo userInfo) {
        // @RequestHeader("Authorization")String token
        userInfo.setId(UserHolder.getId());
        //调用service
        userInfoService.save(userInfo);
        return ResponseEntity.ok(null);
    }

    /*
     * 首次登录上传用户头像
     * */
    @PostMapping("/loginReginfo/head")
    public ResponseEntity upHead(MultipartFile headPhoto) throws IOException {
        // @RequestHeader("Authorization") String token
        // 调用service
        userInfoService.updateHead(headPhoto, UserHolder.getId());
        return ResponseEntity.ok(null);
    }




}
